import React from 'react'
import Component, { mapStateToProps, mapDispatchToProps } from '@components/Component'
import PropTypes from 'prop-types'
import { Table } from 'antd'
import { connect } from 'react-redux'

function formatMoney (v) {
  if (v !== undefined && v !== null) {
    return `${v}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  }
  return 0
}

function getColumn () {
  return [
    {
      title: '仲裁员姓名',
      dataIndex: 'name',
      key: 'name'
    },
    {
      title: '仲裁员报酬',
      dataIndex: 'amount',
      key: 'amount',
      align: 'right',
      render: (v) => {
        return formatMoney(v)
      }
    },
    {
      title: '裁决书制作报酬',
      dataIndex: 'closuredoc_amount',
      key: 'closuredoc_amount',
      align: 'right',
      render: (v) => {
        return formatMoney(v)
      }
    },
    {
      title: '办案交通、通讯费补贴/人',
      dataIndex: 'subsidy_amount',
      key: 'subsidy_amount',
      align: 'right',
      render: (v) => {
        return formatMoney(v)
      }
    },
    {
      title: '案号',
      dataIndex: 'caseno_desc',
      key: 'caseno_desc',
      render: (v, l) => {
        return v || l.counter_caseno_desc
      }
    },
    {
      title: '仲裁员实发各项报酬、补贴金额',
      dataIndex: 'real_amount',
      key: 'real_amount',
      align: 'right',
      render: (v) => {
        return formatMoney(v)
      }
    }
  ]
}

class Main extends Component {
  state = {
    loading: false
  }

  componentDidMount () {
  }

  render () {
    return (
      <div style={{ padding: '0 24px 24px 24px' }}>
        <Table rowKey='id' pagination={false} columns={getColumn()} loading={this.state.loading} dataSource={this.props.data} />
      </div>
    )
  }
}

Main.proptypes = {
  caseDetail: PropTypes.object,
  userInfo: PropTypes.object,
  instance: PropTypes.object,
  formRef: PropTypes.object,
  dictionaries: PropTypes.object,
  data: PropTypes.array
}

Main.defaultProps = {
  caseDetail: {},
  userInfo: {},
  instance: {},
  formRef: {},
  dictionaries: {},
  data: []
}

const mapState = mapStateToProps(function (state) {
  return {
    userInfo: state.basic.userInfo
  }
})

const mapDispatch = mapDispatchToProps(function (dispatch) {
  return {

  }
})

export default connect(mapState, mapDispatch)(Main)
